#include "interface_pkg/srv/add_two_int.hpp"
#include <rclcpp/rclcpp.hpp>

class ServiceServerNode : public rclcpp::Node {
public:
  ServiceServerNode(std::string node_name) : rclcpp::Node(node_name) {
    RCLCPP_INFO(this->get_logger(), "Service Server Node: %s",
                node_name.c_str());
    service_ = this->create_service<interface_pkg::srv::AddTwoInt>(
        "add_two_int", std::bind(&ServiceServerNode::service_callback, this,
                                 std::placeholders::_1, std::placeholders::_2));
  }

private:
  rclcpp::Service<interface_pkg::srv::AddTwoInt>::SharedPtr service_;

  void service_callback(
      const std::shared_ptr<interface_pkg::srv::AddTwoInt::Request> request,
      std::shared_ptr<interface_pkg::srv::AddTwoInt::Response> response) {
    RCLCPP_INFO(this->get_logger(), "Service callback called");
    response->sum = request->a + request->b;
    return;
  }
};

int main(int argc, char *argv[]) {
  rclcpp::init(argc, argv);
  auto node = std::make_shared<ServiceServerNode>("add_two_int_node");
  rclcpp::spin(node);
  rclcpp::shutdown();
  return 0;
}